<template lang="pug">
  d2-container(:filename="filename")
    el-row
        el-col(:span="12")
            el-card(shadow="never")
                div(slot="header",class="clearfix")
                    span 胰岛素泵品牌管理
                el-row
                  el-col(:span="12")
                    el-form(size="small",:inline="true")
                      el-form-item
                        submit-button(type="danger",@click="deletePumpBrands",:loading="deleting")
                          i(class="el-icon-delete")
                          span 删除
                      el-form-item
                        refresh-button(:loading="querying",@click="getInsulinPumps")
                        
                  el-col(:span="12")


                el-table(:data="paged.items",:show-overflow-tooltip="true",border,@selection-change="selectionChange")
                    el-table-column(type="selection",width="50")
                    el-table-column(prop="name",label="胰岛素泵品牌的")
                    el-table-column(label="#",width="100px",align="center")
                      template(slot-scope="scope")
                        el-button(type="text",@click="editClick(scope.row)")
                          i(class="el-icon-edit")
                          span 编辑
                    

                awesome-pagination(:total="paged.totalCount",:page="page",@change="getInsulinPumps")
        el-col(:span="11",:offset="1")
            pump-brand-create(@success="getInsulinPumps")
            div(style="padding:5px 0")
            pump-brand-edit(@success="getInsulinPumps",:id="editId",:visible.sync="editVisible")
</template>

<script>
import Vue from "vue";
import { AwesomePagination } from "awesome-element-ui";
Vue.use(AwesomePagination);

import axios from "@/plugin/axios";
import PageList from "@/mixins/PageList";

import PumpBrandCreate from "./PumpBrandCreate";
Vue.component(PumpBrandCreate.name, PumpBrandCreate);

import PumpBrandEdit from "./PumpBrandEdit";
Vue.component(PumpBrandEdit.name, PumpBrandEdit);

export default {
  name: "user-index",
  mixins: [PageList],
  data() {
    return {
      filename: __filename,
      /**请求接口返回 */
      paged: {},
      filter: {},
      deleting: false,
      editId: null,
      editVisible: false
    };
  },
  methods: {
    getInsulinPumps() {
      this.querying = true;
      axios({
        method: "post",
        url: "PumpBrand/GetPumpBrands",
        data: { page: this.page, filter: this.filter }
      })
        .then(paged => this.getInsulinsSuccess(paged))
        .catch(() => (this.querying = false));
    },
    getInsulinsSuccess(paged) {
      this.querying = false;
      this.paged = paged;
    },
    deletePumpBrands() {
      this.isDeleteConfirm().then(() => {
        this.deleting = true;
        axios({
          method: "post",
          url: "PumpBrand/delete",
          data: { ids: this.selectedIds }
        })
          .then(t => {
            this.deleting = false;
            this.getInsulinPumps();
          })
          .catch(t => (this.deleting = false));
      });
    },
    editClick(row) {
      this.editId = row.id;
      this.editVisible = true;
    }
  },
  created() {
    this.getInsulinPumps();
  }
};
</script>
